package com.zf.controller;


import com.zf.mapper.flightMapper;
import com.zf.pojo.flight;
import com.zf.service.flightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Pageable;
import java.util.List;

@RestController
public class flightController {

    @Autowired
    flightService flightService;

    @GetMapping("/flight")
    @CrossOrigin(value = "http://localhost:8080", maxAge = 1800, allowedHeaders = "*")
    public List<flight> queryFlightList(){
        return   flightService.queryFlight();
    }

    @ResponseBody
    @PostMapping("/deleteFlight/{flightNumber}")
    @CrossOrigin(value = "http://localhost:8080", maxAge = 1800, allowedHeaders = "*")
    public List<flight>  deleteFlight(@PathVariable String  flightNumber){

        flightService.deleteFlight(flightNumber);
        return flightService.queryFlight();
     }

     @ResponseBody
     @PostMapping("/minPrice/{startPlace}/{endPlace}")
     @CrossOrigin(value = "http://localhost:8080", maxAge = 1800, allowedHeaders = "*")
    public List<flight> queryMinPrice(@PathVariable String startPlace,@PathVariable String  endPlace){
        return  flightService.queryMinPrice(startPlace,endPlace);
     }

    @ResponseBody
    @PostMapping("/minTime/{startPlace}/{endPlace}")
    @CrossOrigin(value = "http://localhost:8080", maxAge = 1800, allowedHeaders = "*")
    public List<flight> queryMinTime(@PathVariable String startPlace,@PathVariable String  endPlace){
        return  flightService.queryMinTime(startPlace,endPlace);
    }


}
